package com.ease.actionscript.mapping.mapper;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 
 * @author nathanleewei
 * 
 */
public class ServiceManagerClassMapper extends AbstractActionScriptTypeMapper {

	public static final String PREFIX_SERVICEMANAGER = "ServiceManager";

	private String className;

	private List<Class<?>> remotingDestinationClassList;

	protected String serviceManagerClassName(String destinationProjectName) {
		return PREFIX_SERVICEMANAGER + camelProjectName(destinationProjectName);
	}

	public void prepare() {

		String destinationProjectName = buildDestinationProjectName(this.getProjectName());

		className = serviceManagerClassName(destinationProjectName);
		//

		// String destinationProjectName = this.getProjectName().replaceAll(".java.api", ".java").replaceAll(".java",
		// ".flex.remoting");

		destinationPath = actionScriptMappingContext.getFlexWorkspacePath() + "/" + destinationProjectName + "/src/com/ease/flex/remoting/";

		destinationFileName = className + ".as";
	}

	protected void optimize() {
		super.optimize();

		Set<Class<?>> remotingDestinationClasses = this.getActionScriptMappingContext().getRemotingDestinationClasses(this.projectName);
		if (null != remotingDestinationClasses) {
			remotingDestinationClassList = new ArrayList<Class<?>>(remotingDestinationClasses);
			sort(remotingDestinationClassList);
			remotingDestinationClassList = escapeEmpty(remotingDestinationClassList);
		}
	}

	/**
	 * @return the remotingDestinationClassList
	 */
	public List<Class<?>> getRemotingDestinationClassList() {
		return remotingDestinationClassList;
	}

	/**
	 * @param remotingDestinationClassList
	 *            the remotingDestinationClassList to set
	 */
	public void setRemotingDestinationClassList(List<Class<?>> remotingDestinationClassList) {
		this.remotingDestinationClassList = remotingDestinationClassList;
	}

	/**
	 * @return the className
	 */
	public String getClassName() {
		return className;
	}

	/**
	 * @param className
	 *            the className to set
	 */
	public void setClassName(String className) {
		this.className = className;
	}

}
